package org.stone.project.tx.service.impl;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.stone.project.tx.handle.MsgSendUserTypeHandler;
import org.stone.project.tx.model.Message;
import org.stone.project.tx.service.MsgSendUserTypeHandlerAdapter;
import org.stone.project.tx.sysEnum.ReceiveType;

import java.util.Map;

@Service
public class MsgSendUserTypeHandlerAdapterImpl implements MsgSendUserTypeHandlerAdapter {
    @Autowired
    public Map<ReceiveType, MsgSendUserTypeHandler> sendMsgHandlerMap;

    @Override
    public void sendMsg(Message msg) {
        ReceiveType instance = ReceiveType.getInstance(msg.getReceiveType());
        if (ObjectUtil.isNotNull(instance)){
            MsgSendUserTypeHandler msgSendUserTypeHandler = sendMsgHandlerMap.get(instance);
            if (ObjectUtil.isNotNull(msgSendUserTypeHandler)){
                msgSendUserTypeHandler.sendMsg(msg);
                return;
            }else {
                throw new IllegalArgumentException("发送类型错误，不支持该类");
            }
        }
        throw new IllegalArgumentException("类型错误，不支持该类");
    }
}
